<?php

namespace frontend\modules\yii\models;

use Yii;
use yii\data\ActiveDataProvider;

/**
 * This is the model class for table "frame_catalogue".
 *
 * @property int $id
 * @property string $cname The name of catalogue.
 * @property int $created_at The create time of this catalogue
 * @property int $updated_at The last update time of this catalogue
 */
class FrameCatalogue extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'frame_catalogue';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['created_at', 'updated_at'], 'integer'],
            [['cname'], 'string', 'max' => 100],
            [['cname'], 'required'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cname' => 'Name',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function search($params)
    {
        $query = self::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pagesize' => 10
            ],
        ]);

        // 从参数的数据中加载过滤条件，并验证
        if (!($this->load($params))) {
            return $dataProvider;
        }

        // 增加过滤条件来调整查询对象
        $query->andFilterWhere(['like', 'name', $this->name]);
    }

}
